css: Move special case for 0px borders
authorBenjamin Otte <otte@redhat.com>
Mon, 16 Jul 2012 11:42:18 +0000 (13:42 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 28 Aug 2012 13:40:56 +0000 (15:40 +0200)
This is in preparation for the next commits.

gtk/gtkcssnumbervalue.c
gtk/gtkcssstylepropertyimpl.c

index c929f1d2740d273d4427e4f6ce6af705d1cbf53e..479662c22bab286c67b5d12c777161a18d1400eb 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "gtkcssnumbervalueprivate.h"
 
+#include "gtkcssenumvalueprivate.h"
 #include "gtkstylepropertyprivate.h"
 
 struct _GtkCssValue {
@@ -38,6 +39,40 @@ gtk_css_value_number_compute (GtkCssValue     *number,
                               guint            property_id,
                               GtkStyleContext *context)
 {
+  GtkBorderStyle border_style;
+
+  /* I don't like this special case being here in this generic code path, but no idea where else to put it. */
+  switch (property_id)
+    {
+      case GTK_CSS_PROPERTY_BORDER_TOP_WIDTH:
+        border_style = _gtk_css_border_style_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_STYLE));
+        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+          return _gtk_css_number_value_new (0, GTK_CSS_PX);
+        break;
+      case GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH:
+        border_style = _gtk_css_border_style_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_RIGHT_STYLE));
+        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+          return _gtk_css_number_value_new (0, GTK_CSS_PX);
+        break;
+      case GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH:
+        border_style = _gtk_css_border_style_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_STYLE));
+        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+          return _gtk_css_number_value_new (0, GTK_CSS_PX);
+        break;
+      case GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH:
+        border_style = _gtk_css_border_style_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_LEFT_STYLE));
+        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+          return _gtk_css_number_value_new (0, GTK_CSS_PX);
+        break;
+      case GTK_CSS_PROPERTY_OUTLINE_WIDTH:
+        border_style = _gtk_css_border_style_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_OUTLINE_STYLE));
+        if (border_style == GTK_BORDER_STYLE_NONE || border_style == GTK_BORDER_STYLE_HIDDEN)
+          return _gtk_css_number_value_new (0, GTK_CSS_PX);
+        break;
+      default:
+        break;
+    }
+
   switch (number->unit)
     {
     default:
index bf7fa993f80f2fddab8a464f0dfb8167a9365291..840e3aec871471b4f78a6342b7bf74dffc97304a 100644 (file)
@@ -831,18 +831,7 @@ compute_border_width (GtkCssStyleProperty    *property,
                       GtkStyleContext        *context,
                       GtkCssValue            *specified)
 {
-  GtkBorderStyle border_style;
-  
-  /* The -1 is magic that is only true because we register the style
-   * properties directly after the width properties.
-   */
-  border_style = _gtk_css_border_style_value_get (_gtk_style_context_peek_property (context, _gtk_css_style_property_get_id (property) - 1));
-
-  if (border_style == GTK_BORDER_STYLE_NONE ||
-      border_style == GTK_BORDER_STYLE_HIDDEN)
-    return _gtk_css_number_value_new (0, GTK_CSS_PX);
-  else
-    return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
+  return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 static GtkCssValue *
@@ -1107,8 +1096,8 @@ _gtk_css_style_property_init_properties (void)
                                           query_length_as_int,
                                           assign_length_from_int,
                                           _gtk_css_number_value_new (0.0, GTK_CSS_PX));
-  /* IMPORTANT: compute_border_width() requires that the border-width
-   * properties be immeditaly followed by the border-style properties
+  /* IMPORTANT: the border-width properties must come after border-style properties,
+   * they depend on them for their value computation.
    */
   gtk_css_style_property_register        ("border-top-style",
                                           GTK_CSS_PROPERTY_BORDER_TOP_STYLE,